using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace Entity
{
    public class TblNewsletterGroupExtended : TblNewsletterGroup
    {
        public static List<TblNewsletterGroup> GetAllActiveNewsletterGroup()
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_NEWSLETTERGROUP_GET_ALL_ACTIVE_NEWSLETTER_GROUP);
            GenerateCollectionFromReader reader = new GenerateCollectionFromReader(GenerateTblNewsletterGroupCollectionFromReader);
            List<TblNewsletterGroup> objCollection = ((List<TblNewsletterGroup>)ExecuteReaderCmd(sqlCmd, reader));

            return objCollection;
        }

        public static int GetAllTblNewsletterGroupCountByGroupName(string SubscriberGroupName)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();

            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            AddParameterToSqlCmd(sqlCmd, "@SubscriberGroupName", SqlDbType.NVarChar, 500, ParameterDirection.Input, SubscriberGroupName);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_NEWSLETTER_GROUP_GET_ALL_TBL_NEWSLETTER_GROUP_COUNT);
            ExecuteScalarCmd(sqlCmd);

            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }

        public static List<TblNewsletterGroup> GetAllTblNewsletterGroupByGroupName(string SortBy, int startRow, object PageSize, string SubscriberGroupName)
        {
            //Validate Input
            if (SortBy == "")
                SortBy = "NewsletterGroupId";

            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@orderby", SqlDbType.VarChar, 50, ParameterDirection.Input, SortBy);
            AddParameterToSqlCmd(sqlCmd, "@startrow", SqlDbType.Int, 0, ParameterDirection.Input, startRow);
            AddParameterToSqlCmd(sqlCmd, "@pagesize", SqlDbType.Int, 0, ParameterDirection.Input, PageSize);
            AddParameterToSqlCmd(sqlCmd, "@SubscriberGroupName", SqlDbType.NVarChar, 500, ParameterDirection.Input, SubscriberGroupName);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_NEWSLETTER_GROUP_GET_ALL_TBL_NEWSLETTER_GROUP_BY_GROUP);

            GenerateCollectionFromReader test = new GenerateCollectionFromReader(GenerateTblNewsletterGroupCollectionFromReader);
            List<TblNewsletterGroup> objCollection = ((List<TblNewsletterGroup>)ExecuteReaderCmd(sqlCmd, test));
            return objCollection;
        }

        private const string SP_TBL_NEWSLETTERGROUP_GET_ALL_ACTIVE_NEWSLETTER_GROUP = "sp_TblNewsletterGroup_Get_All_Active_Newsletter_Group";
        private const string SP_TBL_NEWSLETTER_GROUP_GET_ALL_TBL_NEWSLETTER_GROUP_BY_GROUP = "sp_TblNewsletterGroup_Get_All_Tbl_Newsletter_Group_By_Group";
        private const string SP_TBL_NEWSLETTER_GROUP_GET_ALL_TBL_NEWSLETTER_GROUP_COUNT = "sp_TblNewsletter_Group_Get_All_Tbl_Newsletter_Group_Count";
    }
}
